﻿using B.S.BaseData.ErrorCode;
using B.S.BaseData.ReadAPI.Applications.Commands.CarAndPeopleCommand;
using B.S.BaseData.ReadAPI.Applications.Commands.DangerousCommand;
using B.S.BaseData.ReadAPI.Dtos;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.S.BaseData.ReadAPI.Controllers
{
    /// <summary>
    /// 事故管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class DangerousController : ControllerBase
    {
        /// <summary>
        /// 中介者
        /// </summary>
        IMediator mediator;
        /// <summary>
        /// 日志
        /// </summary>
        ILogger<DangerousController> logger;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator">中介者</param>
        /// <param name="logger">日志</param>
        public DangerousController(IMediator mediator, ILogger<DangerousController> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 事故列表
        /// </summary>
        /// <param name="cmd">查询条件</param>
        /// <returns>返回符合条件的数据</returns>
        [HttpGet]
        public async Task<ApiResult<ApiPaging<List<PagingDangerousRespDto>>>>PagingDangerous([FromQuery]PagingCommand cmd)
        {
            try
            {
                var result = await mediator.Send(cmd);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("事故列表出错" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 车牌列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<CarAndPeopleRespDto>>>CarSelect()
        {
            try
            {
                CarCommand cmd = new CarCommand();
                var result  = await mediator.Send(cmd);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("车牌列表出错" + ex.Message);
                throw;
            }
        }
        /// <summary>
        /// 事故人列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<List<CarAndPeopleRespDto>>> PeopleSelect()
        {
            try
            {
                PeopleCommand cmd = new PeopleCommand();
                var result = await mediator.Send(cmd);
                return result;
            }
            catch (Exception ex)
            {
                logger.LogError("事故人列表出错" + ex.Message);
                throw;
            }
        }
    }
}
